(deftemplate doua
    (slot nume)
    (slot x)
    (slot y))

(foreach ?d (create$ d1 d2 d3 d4)
    (foreach ?i (create$ 1 2 3 4)
        (foreach ?j (create$ 1 2 3 4)
            (assert(doua(nume ?d)(x ?i)(y ?j)))
            )
        )
    )

(facts)

(defrule rezolvare
    ?id1<-(doua(nume d1)(x ?x1)(y ?y1))
    ?id2<-(doua(nume d2)(x ?x2)(y ?y2))
    ?id3<-(doua(nume d3)(x ?x3)(y ?y3))
    ?id4<-(doua(nume d4)(x ?x4)(y ?y4))

    (test(neq ?x1 ?x2))
    (test(neq ?x1 ?x3))
    (test(neq ?x1 ?x4))
    (test(neq ?x2 ?x3))
    (test(neq ?x2 ?x4))
    (test(neq ?x3 ?x4))
    (test(neq ?y1 ?y2))
    (test(neq ?y1 ?y3))
    (test(neq ?y1 ?y4))
    (test(neq ?y2 ?y3))
    (test(neq ?y2 ?y4))
    (test(neq ?y3 ?y4))
    
    (test(neq(- ?x1 ?y1)(- ?x2 ?y2)))
    (test(neq(- ?x1 ?y1)(- ?x3 ?y3)))
    (test(neq(- ?x1 ?y1)(- ?x4 ?y4)))
    (test(neq(- ?x2 ?y2)(- ?x3 ?y3)))
    (test(neq(- ?x2 ?y2)(- ?x4 ?y4)))
    (test(neq(- ?x3 ?y3)(- ?x4 ?y4)))
    
    (test(neq(+ ?x1 ?y1)(+ ?x2 ?y2)))
    (test(neq(+ ?x1 ?y1)(+ ?x3 ?y3)))
    (test(neq(+ ?x1 ?y1)(+ ?x4 ?y4)))
    (test(neq(+ ?x2 ?y2)(+ ?x3 ?y3)))
    (test(neq(+ ?x2 ?y2)(+ ?x4 ?y4)))
    (test(neq(+ ?x3 ?y3)(+ ?x4 ?y4)))
    =>
    (retract ?id1)
    (retract ?id2)
    (retract ?id3)
    (retract ?id4)
    
    (printout t " Solutie problema damelor:" crlf)
    (printout t " X1 :" ?x1 " Y1 :" ?y1 crlf)
    (printout t " X2 :" ?x2 " Y2 :" ?y2 crlf)
    (printout t " X3 :" ?x3 " Y1 :" ?y3 crlf)
    (printout t " X4 :" ?x4 " Y1 :" ?y4 crlf)
    )

(run)